package com.fileServer.controller;

import com.fileServer.result.Result;
import com.fileServer.service.FileServerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 大忽悠
 * @create 2022/9/15 11:09
 */
@Validated
@RestController
@RequiredArgsConstructor
@Api(tags="文件服务请求")
public class FileServerController {
    private final FileServerService fileServerService;

    @PostMapping("/upload")
    @ApiOperation("上传文件")
    public Result uploadFile(@RequestPart("file") MultipartFile multipartFile
            ,@RequestParam("bucketName")String bucketName,@RequestParam("dirName")String dirName){
        return Result.success(fileServerService.uploadFile(bucketName,multipartFile,dirName));
    }

    @PostMapping("/uploadZip")
    @ApiOperation("上传压缩课程文件")
    public Result uploadZipCourseFile(@RequestPart("file") MultipartFile multipartFile
            ,@RequestParam("bucketName")String bucketName,@RequestParam("dirName")String dirName){
        return Result.success(fileServerService.uploadZipFile(bucketName,multipartFile,dirName));
    }

    @PostMapping("/delete")
    @ApiOperation("删除文件")
    public Result deleteFile(@RequestParam("bucketName")String bucketName,
                             @RequestParam("fileName")String fileName){
        return Result.success(fileServerService.deleteFile(bucketName,fileName));
    }

}
